{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b48281b0-80c1-4ed8-8e09-8c046cbecd18",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/llama-index-integrations/tools/llama-index-tools-vectara-query/examples/vectara_query.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2762271-0db4-4d50-aa50-036d01926a7d",
   "metadata": {},
   "source": [
    "## Vectara Query Tool"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4452df2a-976b-4e1c-9f9b-2fa983569948",
   "metadata": {},
   "source": [
    "Please note that this example notebook is only for Vectara Query tool versions >=0.3.0\n",
    "\n",
    "To get started with Vectara, [sign up](https://vectara.com/integrations/llamaindex) (if you haven't already) and follow our [quickstart](https://docs.vectara.com/docs/quickstart) guide to create a corpus and an API key.\n",
    "\n",
    "Once you have done this, add the following variables to your environment:\n",
    "\n",
    "`VECTARA_CORPUS_KEY`: The corpus key for the Vectara corpus that you want your tool to search for information.\n",
    "\n",
    "`VECTARA_API_KEY`: An API key that can perform queries on this corpus.\n",
    "\n",
    "You are now ready to use the Vectara query tool.\n",
    "\n",
    "To initialize the tool, provide your Vectara information and any query parameters that you want to adjust, such as the reranker, summarizer prompt, etc. To see the entire list of parameters, see the [VectaraQueryToolSpec class definition](https://github.com/run-llama/llama_index/blob/05828d6d099e78df51c76b8c98aa3ecbd45162ec/llama-index-integrations/tools/llama-index-tools-vectara-query/llama_index/tools/vectara_query/base.py#L11)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "adbd9f2c-1cc9-4220-a117-7099a248d855",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import and initialize our tool spec\n",
    "# pip install -U llama-index-tools-vectara-query\n",
    "\n",
    "from llama_index.tools.vectara_query.base import VectaraQueryToolSpec\n",
    "\n",
    "tool_spec = VectaraQueryToolSpec()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac3f03a4-2448-4ef2-8aa8-e6c536875a0e",
   "metadata": {},
   "source": [
    "After initializing the tool spec, we can provide it to our agent. For this notebook, we will use the OpenAI Agent, but our tool can be used with any type of agent. You will need your own OpenAI API key to run this notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f9fe90d-4a54-416f-a0ed-81c3de614487",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Setup OpenAI Agent\n",
    "import os\n",
    "from llama_index.core.agent.workflow import FunctionAgent\n",
    "from llama_index.llms.openai import OpenAI\n",
    "\n",
    "agent = FunctionAgent(\n",
    "    tools=tool_spec.to_tool_list(),\n",
    "    llm=OpenAI(model=\"gpt-4.1\"),\n",
    ")\n",
    "\n",
    "print(await agent.run(\"What are the different types of electric vehicles?\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
